<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="" method="post">
	<input type="hidden" id="storeid" name="storeid" value="${storeEntity.id }">
	<input type="hidden" id="dbid" name="dbid" value="${databaseresource.id }">
	<input type="hidden" id="olddbid" name="olddbid" value="${databaseresource.id }">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.resourcemanagement.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.list.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.list.title") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %></label>
						<span class="res">${storeEntity.number }</span> 
					</li>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %></label>
						<span class="res">${storeEntity.name }</span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.ip") %></label>
						<span><input type="text" id="ip" name="ip" value="${databaseresource.ip }"></span>
					</li>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.dbname") %></label>
						<span><input type="text" id="dbname" name="dbname" value="${databaseresource.dbname }" readonly="readonly"></span>
					</li>
				</ul>
				<ul>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.totalconn") %></label>
						<span><input type="text" id="totalconn" name="totalconn" value="${databaseresource.totalconn }" readonly="readonly"></span>
					</li>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.usedconn") %></label>
						<span><input type="text" id="usedconn" name="usedconn" value="${databaseresource.usedconn }" readonly="readonly"></span>
					</li>
				</ul>
			</div>
			<div class="button-group">
				<input type="button" class="btn btn-default" onclick="assign()" value="<%=MessageResourcesUtils.getMessage(request, "common.button.binding") %>" />
	  			<input type="button" class="btn btn-default" id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
    	</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(
			function() {
				
				$("#ip").issNewMagnifier({
					title: '<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.databasemagnifiertitle") %>',
					url: '${systemctx}/publicMagnifier/publicMagnifier.json',
					sortName : 'modifytime',
					sortOrder : 'desc',
					linkName: 'ip',
					callSqlKey: 'queryDatabaseResourceMagnifierSql',
					changeIgnore: ['ip'],
					columns: [[
						{title:'<%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.ip") %>',field:'ip',width:110,sortable:true,align:'left',formel:'ip'},
						{title:'<%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.dbname") %>',field:'dbname',width:110,sortable:true,align:'left',formel:'dbname'},
						{title:'<%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.totalconn") %>',field:'totalconn',width:110,sortable:true,align:'left',formel:'totalconn'},
						{title:'<%=MessageResourcesUtils.getMessage(request, "systemmanage.databaseresource.list.usedconn") %>',field:'usedconn',width:110,sortable:true,align:'left',formel:'usedconn'},
						{field:'id',hidden:true,formel:'dbid'}
					]],
					onBeforeOpen:function(p){
				      var queryParams = {
				    		  ip: '%' + $("#ip").val() + '%',
				    		  statusid: <%=SysConstant.RecordStatus.VALID %>
				      };
				      return queryParams;
				    }
				});
				
				$('#butRest').click(function() {
					$("#ipmagnifier").val('');
					$("#dbnamemagnifier").val('');
					$("#username").val('');
					$("#totalconn").val('');
					$("#usedconn").val('');
					$("#dbid").val('');
				});
				
				$('#butReturn').click(function(){
					parent.document.location.reload();
				    $.fn.closeIssWindow();
				});
						
			});
	function assign()
	{
		var dbid = $("#dbid");
		var olddbid= $("#olddbid");
		var usedconn = $("#usedconn");
		var totalconn = $("#totalconn");
		if (dbid.val() == '') {
			messageAlert("<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.add.selectdatabase") %>");
			return;
		} else {
	       if(Number(usedconn.val()) >= Number(totalconn.val()))
	       {
	    	alert("<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.add.outconn") %>");
	       } else {
	       	if(confirm("<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.add.confirmbinding") %>"))
       		{
	       		doAssign();
       		}
	       }
		}
	}
		
	function doAssign() {
		$('#form1').attr('action','${systemctx}/systemmanage/databasebinding/bindingDatabaseResource.json').submit();
	}
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>